import java.util.Arrays;

//冒泡排序 测试方法
public class BubbleSort2 {
    public static void main(String[] args) {
        int[] array = {1, 3, 2, 5, 4, 6, 7, 9, 8, 0};
        int compareCount=0;
        int swapCount=0;
        long startTime=System.currentTimeMillis();

        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - 1 - i; j++) {
                compareCount++;
                if (array[j] > array[j + 1]) {
                    int num = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = num;
                    swapCount++;
                }
                System.out.println(Arrays.toString(array));
            }
            System.out.println();
        }

        long endTime=System.currentTimeMillis();

        System.out.println("对比次数: "+compareCount);
        System.out.println("换位次数: "+swapCount);
        System.out.println("耗时: "+(endTime-startTime));
    }
}
